<template>
  <div class="login-bg">
    <div class="login-container">
      <div class="login-logo">
        <div class="logo-img-wrap">
          <img src="../../public/img/图片.jpg" alt="logo" />
        </div>
        <h2>非敏感安全互联网系统管理平台</h2>
      </div>
      <el-form :model="loginForm" :rules="rules" ref="loginFormRef" label-width="80px" class="login-form">
        <el-form-item label="用户名" prop="name">
          <el-input v-model="loginForm.name" autocomplete="off" prefix-icon="el-icon-user" />
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input v-model="loginForm.password" type="password" autocomplete="off" prefix-icon="el-icon-lock" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="handleLogin" style="width:100%;">登录</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex';
import axios from '@/utils/index.js'
export default {
  name: 'Login',
  data() {
    return {
      loginForm: {
        name: 'admin',
        password: '123456'
      },
      rules: {
        name: [
          { required: true, message: '请输入用户名', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' },
          { min: 6, message: '密码长度不能少于6位', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    handleLogin() {
      this.$refs.loginFormRef.validate(valid => {
        if (valid) {
          axios.post('/user/login', this.loginForm).then(response => {
            console.log(response.code);
            if (response.code == 0) {
              localStorage.setItem('token', response.token)

            this.$router.push("/layout")
            this.$message.success('登录成功')
             
            }else{
              this.$message.error('登录失败: ' + '请检查用户名或密码')
            }
          }).catch(error => {
            this.$message.error('登录失败: ' + error.message)
          });
        }
      })
    }
  }
}
</script>

<style scoped>
.login-bg {
  min-height: 100vh;
  width: 100vw;
  background: linear-gradient(135deg, #f3f6fa 0%, #e9f0fb 100%);
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-container {
  width: 400px;
  padding: 40px 30px 30px 30px;
  box-shadow: 0 4px 24px 0 rgba(0,0,0,0.10);
  border-radius: 12px;
  background: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.login-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 24px;
}
.logo-img-wrap {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: linear-gradient(135deg, #e9f0fb 0%, #f3f6fa 100%);
  box-shadow: 0 4px 18px #b3c6e8, 0 1px 8px #e9f0fb;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 10px;
  border: 2px solid #fff;
  transition: box-shadow 0.2s;
}
.logo-img-wrap img {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  object-fit: cover;
  box-shadow: 0 2px 8px #b3c6e8;
  border: 2px solid #e9f0fb;
  background: #fff;
  transition: transform 0.2s;
}
.logo-img-wrap:hover {
  box-shadow: 0 8px 32px #b3c6e8;
}
.logo-img-wrap img:hover {
  transform: scale(1.06) rotate(-3deg);
}
.login-logo h2 {
  font-weight: 600;
  color: #409eff;
  margin: 0;
  font-size: 22px;
  letter-spacing: 2px;
  text-shadow: 0 2px 8px #e9f0fb;
}
.login-form {
  width: 100%;
}
::v-deep .el-input__inner {
  border-radius: 6px;
  height: 40px;
  font-size: 16px;
  background: #f3f6fa;
  color: #232526;
  border: 1px solid #b3c6e8;
}
::v-deep .el-input__inner:focus {
  border-color: #409eff;
  background: #fff;
}
::v-deep .el-form-item__label {
  color: #232526 !important;
}
.el-button--primary {
  border-radius: 6px;
  font-size: 16px;
  height: 40px;
  background: linear-gradient(90deg, #e9f0fb 0%, #409eff 100%);
  border: none;
  color: #232526;
}
.el-button--primary:hover {
  background: linear-gradient(90deg, #409eff 0%, #e9f0fb 100%);
  color: #232526;
}
</style>